-
-
Notifications
You must be signed in to change notification settings - Fork 389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
correctly count emojis when composing a post #4152
Conversation
return length | ||
} | ||
|
||
// String.length would count emojis as multiple characters but Mastodon counts them as 1, so we need this workaround | ||
private fun String.perceivedCharterLength(): Int { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perceivedCharacterLength
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
} | ||
|
||
@Test | ||
fun whenTextContainsUrl_onlyEllipsizedURLIsCounted() { | ||
val url = "https://www.google.dk/search?biw=1920&bih=990&tbm=isch&sa=1&ei=bmDrWuOoKMv6kwWOkIaoDQ&q=indiana+jones+i+hate+snakes+animated&oq=indiana+jones+i+hate+snakes+animated&gs_l=psy-ab.3...54174.55443.0.55553.9.7.0.0.0.0.255.333.1j0j1.2.0....0...1c.1.64.psy-ab..7.0.0....0.40G-kcDkC6A#imgdii=PSp15hQjN1JqvM:&imgrc=H0hyE2JW5wrpBM:" | ||
val additionalContent = "Check out this @image #search result: " | ||
insertSomeTextInContent(additionalContent + url) | ||
assertEquals(activity.calculateTextLength(), additionalContent.length + InstanceInfoRepository.DEFAULT_CHARACTERS_RESERVED_PER_URL) | ||
assertEquals(additionalContent.length + InstanceInfoRepository.DEFAULT_CHARACTERS_RESERVED_PER_URL, activity.calculateTextLength()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha oops 🙂
4c1ac51
to
8d0a125
Compare
Mastodon counts post lengths by considering emojis to be single characters, no matter how many unicode code points they are composed of. So "😜" has length 1. Pachli was using `String.length`, which considers "😜" as length 2. Correct the calculation by using a BreakIterator to count the characters in the string, which treats multi-character emojis as a length 1. Poll options had a similar problem, exacerbated by the Mastodon web UI also having the same problem, see mastodon/mastodon#28336. Fix that by creating `MastodonLengthFilter`, an `InputFilter` that does the right thing for regular text that may contain emojis. See also tuskyapp/Tusky#4152, which has the fix for status length but not polls. Co-authored-by: Konrad Pozniak <[email protected]>
Mastodon counts post lengths by considering emojis to be single characters, no matter how many unicode code points they are composed of. So "😜" has length 1. Pachli was using `String.length`, which considers "😜" as length 2. Correct the calculation by using a BreakIterator to count the characters in the string, which treats multi-character emojis as a length 1. Poll options had a similar problem, exacerbated by the Mastodon web UI also having the same problem, see mastodon/mastodon#28336. Fix that by creating `MastodonLengthFilter`, an `InputFilter` that does the right thing for regular text that may contain emojis. See also tuskyapp/Tusky#4152, which has the fix for status length but not polls. --------- Co-authored-by: Konrad Pozniak <[email protected]>
Thx to @evant for the help
closes #4140